/*
 *
 * @ProjectName:    my_umi_app
 * @Package:
 * @ClassName:      menu_api
 * @Description:    获取Menu相关接口
 * @Author:         SuPeiSen
 * @CreateDate:     2020/12/24 3:29 下午
 * @UpdateDate:     2020/12/24 3:29 下午
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */

import { AxiosParam, Requests } from '@/utils/requests';
import { ApiPath } from '@/config/api_config';
import { Local } from '@/utils/cache';
import { MenuListModel } from '@/type/menu_type';
import ex from 'umi/dist';
import { boolToNumOneOrZero } from '@/utils/app_fun';

/**
 * 获取MenuList
 */
export const getMenuListApi = async (postParam: AxiosParam) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'post',
    ApiPath.getMenuList,
    {
      postData: postParam,
    },
  );
  return model;
};

// 删除栏目
export const deleteMenuListApi = async (id: number) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'delete',
    ApiPath.deleteMenu + `${id}`,
  );
  if (model.success) {
    return true;
  }
  return false;
};

// 更新栏目
export const updateMenuList = async (postParam: any) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'put',
    ApiPath.updateMenu,
    {
      postData: postParam,
    },
  );
  return model.success;
};

// 通过ID更新状态
export const updateMenuStatusApi = async (param: {
  id: number;
  status: boolean;
}) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'put',
    ApiPath.updateMenuStatus,
    {
      postData: {
        id: param.id,
        status: boolToNumOneOrZero(param.status),
      },
    },
  );
  return model.success;
};
